
const { ccclass, property } = cc._decorator;

@ccclass
export default class MoveBall extends cc.Component {
    @property(cc.Float)
    moveTime: number = 0.5

    ballTween: cc.Tween = null

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {

    }

    // update (dt) {}

    async tweenMove(posGrp: any[],startPos:cc.Vec2) {
        if (!posGrp.length) return
        this.node.active = true
        this.node.setPosition(startPos)
        this.node.zIndex=999
        for (let i = 0; i < posGrp.length; i++) {
            let grp = []
            for (let j = 0; j < posGrp[i].length; j++) {
                grp.push(posGrp[i][j].getPosition())
            }
            await new Promise((resolve) => {
                this.ballTween = cc.tween(this.node)
                    .bezierTo(this.moveTime, grp[0], grp[1],grp[2])
                    .call(() => {
                        if(i==posGrp.length-1){
                            this.node.active=false
                        }
                        resolve(null)
                    })
                    .start()
            })

        }
    }
}
